package com.qingzhu.controller.orderserver;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingzhu.pojovo.ResultVo;
import com.qingzhu.service.OrderService;
import com.qingzhu.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/order/update")
public class OrderUpdateController extends HttpServlet {
    OrderService orderService = new OrderServiceImpl();
    ObjectMapper objectMapper = new ObjectMapper();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("订单恢复功能...");

        String orderId = req.getParameter("orderId");
        int result = orderService.recoveryOrderById(Integer.parseInt(orderId));
        ResultVo resultVo = result>0 ? new ResultVo(200,"成功恢复一个订单！"):new ResultVo(500,"订单恢复失败！");
        resp.getWriter().write(objectMapper.writeValueAsString(resultVo));
    }
}
